<?php 
$page_security = 'SA_SALESPAYMNT';
$path_to_root = "..";
include_once($path_to_root . "/includes/ui/allocation_cart.inc");
include_once($path_to_root . "/includes/session.inc");
include_once($path_to_root . "/includes/date_functions.inc");
include_once($path_to_root . "/includes/ui.inc");
include_once($path_to_root . "/includes/banking.inc");
include_once($path_to_root . "/includes/data_checks.inc");
include_once($path_to_root . "/sales/includes/sales_db.inc");
//include_once($path_to_root . "/sales/includes/ui/cust_alloc_ui.inc");
include_once($path_to_root . "/reporting/includes/reporting.inc");
include($path_to_root ."/pittycash/includes/db/pittycash_db.inc");

$js = "";
if ($use_popup_windows) {
	$js .= get_js_open_window(900, 500);
}
if ($use_date_picker) {
	$js .= get_js_date_picker();
}
add_js_file('payalloc.js');

page(_($help_context = "Input Kas Bon"), false, false, "", $js);

$Refs = new references();

if (isset($_GET['AddedID'])) {
	$payment_no = $_GET['AddedID'];

	display_notification_centered(_("The customer payment has been successfully entered."));

	submenu_print(_("&Print This Receipt"), ST_CUSTPAYMENT, $payment_no."-".ST_CUSTPAYMENT, 'prtopt');

	display_note(get_gl_view_str(ST_CUSTPAYMENT, $payment_no, _("&View the GL Journal Entries for this Customer Payment")));

//	hyperlink_params($path_to_root . "/sales/allocations/customer_allocate.php", _("&Allocate this Customer Payment"), "trans_no=$payment_no&trans_type=12");

	hyperlink_no_params($path_to_root . "/sales/customer_payments.php", _("Enter Another &Customer Payment"));
	
	display_footer_exit();
}


//----------------------------------------------------------------------------------------------

function can_process()
{
	global $Refs;

		return true;
}

if (isset($_POST['AddPaymentItem'])) {
	$doc = array('ref'=> get_post('ref'), 'date'=>date2sql(Today()),'employee_id' => get_post('employee_id'),
	'amount'=>input_num('amount'),'note'=> get_post('note'));
	add_kas_bon($doc);
	
	unset($_POST);
	unset($_SESSION);
//
//	//Chaitanya : 13-OCT-2011 - To support Edit feature
//	//meta_forward($_SERVER['PHP_SELF'], "AddedID=$payment_no");
//	meta_forward($_SERVER['PHP_SELF'], $new ? "AddedID=$payment_no" : "UpdatedID=$payment_no");
}

//----------------------------------------------------------------------------------------------

function read_customer_data()
{
	global $Refs, $new;

	$myrow = get_customer_habit($_POST['customer_id']);

	$_POST['HoldAccount'] = $myrow["dissallow_invoices"];
	$_POST['pymt_discount'] = $myrow["pymt_discount"];
	
	if ($new && !isset($_POST['charge'])) 
		$_POST['ref'] = $Refs->get_next(ST_CUSTPAYMENT);
}

//----------------------------------------------------------------------------------------------
$new = 1;
$old_ref = 0;	



//----------------------------------------------------------------------------------------------
$_POST['ref'] = $Refs->get_next(ST_KASBON);
$_POST['date'] = Today();

start_form();
    
//	hidden('trans_no', $_POST['trans_no']);
//	hidden('old_ref', $old_ref);

	start_outer_table(TABLESTYLE2, "width=60%", 5);
	table_section(1);

	//if ($new)
//	customer_list_row(_("Employee:"), 'customer_id', null, false, true);
	employee_list_row("Nama Karyawan:", 'employee_id', null, false, true);
    text_row(_("Reference:"), 'ref', null, 20, 40);

	table_section(2);
	label_row("Tanggal: ", Today());
    label_row("Sisa Kas Kecil: ", '');
	//set_global_customer($_POST['customer_id']);




//		table_section(3);

//		date_row(_("Date of Deposit:"), 'DateBanked', '', true, 0, 0, 0, null, true);


		end_outer_table(1);


		start_table(TABLESTYLE, "width=60%");

		amount_row(_("Amount:"), 'amount');

		textarea_row(_("Keperluan:"), 'note', null, 50, 4);
		end_table(1);

		br();

	    submit_center('AddPaymentItem', "Simpan Kasbon", true, '', 'default');


	br();

end_form();
end_page();

?>